package com.adcc.loadsheet.billing.service.impl;

import com.adcc.loadsheet.billing.entity.PbDepartmentEntity;
import com.adcc.loadsheet.billing.entity.PbStaffEntity;
import com.adcc.loadsheet.billing.entity.ScAirlinesEntity;
import com.adcc.loadsheet.billing.entity.ScAirportEntity;
import com.adcc.loadsheet.billing.entity.chargerule.BillingRuleEntity;
import com.adcc.loadsheet.billing.entity.contractuser.ContractUserEntity;
import com.adcc.loadsheet.billing.security.UserInfo;
import com.adcc.loadsheet.billing.service.ContractUserService;
import com.adcc.loadsheet.billing.util.BillingTools;
import com.adcc.loadsheet.billing.util.DateTimeUtil;
import com.adcc.loadsheet.billing.util.LogUtil;
import com.adcc.loadsheet.billing.util.SystemOperationLogType;
import com.adcc.loadsheet.billing.vo.PbStaffTreeVO;
import com.adcc.loadsheet.billing.vo.ScAirlinesEntityVO;
import com.adcc.loadsheet.billing.vo.ScAirportEntityVO;
import com.adcc.loadsheet.billing.vo.chargerule.BillingRuleEntityVO;
import com.adcc.loadsheet.billing.vo.contractuser.ContractUserEntityVO;
import com.adcc.loadsheet.billing.vo.contractuser.ContractUserTreeVO;
import com.adcc.loadsheet.billing.vo.contractuser.ContractUserType;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 合同用户表Service实现类
 * Created by zhaoml on 2020/4/13.
 */
@Service
public class ContractUserServiceImpl extends BasisServiceImpl implements ContractUserService {

    //根据条件获取合同用户
    @Override
    public List<ContractUserEntity> select(Map<String, Object> map){
        List<ContractUserEntity> list = contractUserEntityMapper.select(map);
        return list;
    }

    //获取合同用户Tree
    @Override
    public List<ContractUserTreeVO> getTreeNode(){
        List<ContractUserTreeVO> vos = Lists.newArrayList();

        //航司根节点
        String airlines_pId = ContractUserType.AIRLINES.toString();
        ContractUserTreeVO rootNode_airlines =
                new ContractUserTreeVO(airlines_pId,"0","航司",true,true);
        vos.add(rootNode_airlines);

        //机场根节点
        String airport_pId = ContractUserType.AIRPORT.toString();
        ContractUserTreeVO rootNode_airport =
                new ContractUserTreeVO(airport_pId,"0","机场",true,true);
        vos.add(rootNode_airport);

        //合同用户
        Map<String, Object> map = Maps.newHashMap();
        //合同用户可以查询自己的计费规则，无修改权限且只能查看自己的计费规则
        if(!userContext.getCurrentUser().isSuperAdmin()){
            map.put("PB_LOGIN_ID",userContext.getCurrentUser().getUsername());
        }
        List<ContractUserEntity> list_airport = contractUserEntityMapper.select(map);
        list_airport.stream().forEach(
                entity -> vos.add(new ContractUserTreeVO(entity,true,false)));

        return vos;
    }

    //查询合同用户
    @Override
    public ContractUserEntityVO findByContractUserId(Map<String, Object> paramMap){
        Integer contractUserId = Integer.valueOf(paramMap.get("contractUserId").toString());
        ContractUserEntity contractUserEntity = contractUserEntityMapper.selectByPrimaryKey(contractUserId);
        ContractUserEntityVO vo = contractUserEntity.toVO();
        return vo;
    }

    //查询合同用户
    @Override
    public ContractUserEntity selectByPrimaryKey(Integer contractUserId){
        ContractUserEntity contractUserEntity = contractUserEntityMapper.selectByPrimaryKey(contractUserId);
        return contractUserEntity;
    }

    //根据用户简称查询对应实体
    @Override
    public ContractUserEntity findByUserAbbrev(String userAbbrev){
        return contractUserEntityMapper.findByUserAbbrev(userAbbrev);
    }

    //编辑合同用户
    @Override
    @Transactional(transactionManager = "mysqlTransactionManager")
    public ContractUserEntity edit(ContractUserEntityVO contractUserEntityVO){
        String res = "";
        String logContent = "";     //日志内容
        try {
            ContractUserEntity contractUserEntity = contractUserEntityVO.toEntity();
            UserInfo user = userContext.getCurrentUser();
            contractUserEntity.setUpdateAt(DateTimeUtil.getNowDate());
            contractUserEntity.setUpdateUser(user.getUsername());
            //保存合同用户
            if(contractUserEntity.getContractUserId() == null){
                contractUserEntity.setCreateAt(DateTimeUtil.getNowDate());
                contractUserEntity.setCreateUser(user.getUsername());
                contractUserEntityMapper.insert(contractUserEntity);
                res = "新增成功";

                //记录操作日志
                LogUtil.operationLog(SystemOperationLogType.ContractUser_Operation.ordinal(), "新增合同用户“" + contractUserEntity.getUserAbbrev() + "”", user.getUsername());
            }else {
                //记录操作日志
                //用户简称
                ContractUserEntity oldContractUserEntity = contractUserEntityMapper.selectByPrimaryKey(contractUserEntity.getContractUserId());
                if(!oldContractUserEntity.getUserAbbrev().equals(contractUserEntity.getUserAbbrev())){
                    logContent += Strings.isNullOrEmpty(logContent) ? "修改合同用户“" + oldContractUserEntity.getUserAbbrev() + "”：" : "";
                    logContent += "用户简称由“" + oldContractUserEntity.getUserAbbrev() + "”修改为“" + contractUserEntity.getUserAbbrev() + "”";
                }
                //用户全称
                String oldUserFullname = Strings.isNullOrEmpty(oldContractUserEntity.getUserFullname()) ? "" : oldContractUserEntity.getUserFullname();
                String newUserFullname = Strings.isNullOrEmpty(contractUserEntity.getUserFullname()) ? "" : contractUserEntity.getUserFullname();
                if(!oldUserFullname.equals(newUserFullname)) {
                    logContent += Strings.isNullOrEmpty(logContent) ? "修改合同用户“" + oldContractUserEntity.getUserAbbrev() + "”：用户全称由“" + oldUserFullname + "”修改为“" + newUserFullname + "”" : "，用户全称由“" + oldUserFullname + "”修改为“" + newUserFullname + "”";
                }
                //类型
                String oldUserType = oldContractUserEntity.getUserType() == 1 ? "机场" : "航司";
                String newUserType = contractUserEntity.getUserType() == 1 ? "机场" : "航司";
                if(oldContractUserEntity.getUserType() != contractUserEntity.getUserType()){
                    logContent += Strings.isNullOrEmpty(logContent) ? "修改合同用户“" + oldContractUserEntity.getUserAbbrev() + "”：类型由“" + oldUserType + "”修改为“" + newUserType + "”" : "，类型由“" + oldUserType + "”修改为“" + newUserType + "”";
                }
                //责任人
                String oldPersonLiable = Strings.isNullOrEmpty(oldContractUserEntity.getPersonLiable()) ? "" : oldContractUserEntity.getPersonLiable();
                String newPersonLiable = Strings.isNullOrEmpty(contractUserEntity.getPersonLiable()) ? "" : contractUserEntity.getPersonLiable();
                if(!oldPersonLiable.equals(newPersonLiable)) {
                    logContent += Strings.isNullOrEmpty(logContent) ? "修改合同用户“" + oldContractUserEntity.getUserAbbrev() + "”：责任人由“" + oldPersonLiable + "”修改为“" + newPersonLiable + "”" : "，责任人由“" + oldPersonLiable + "”修改为“" + newPersonLiable + "”";
                }
                //手机
                String oldMobilephone = Strings.isNullOrEmpty(oldContractUserEntity.getMobilephone()) ? "" : oldContractUserEntity.getMobilephone();
                String newMobilephone = Strings.isNullOrEmpty(contractUserEntity.getMobilephone()) ? "" : contractUserEntity.getMobilephone();
                if(!oldMobilephone.equals(newMobilephone)) {
                    logContent += Strings.isNullOrEmpty(logContent) ? "修改合同用户“" + oldContractUserEntity.getUserAbbrev() + "”：手机由“" + oldMobilephone + "”修改为“" + newMobilephone + "”" : "，手机由“" + oldMobilephone + "”修改为“" + newMobilephone + "”";
                }
                //电话
                String oldTelephone = Strings.isNullOrEmpty(oldContractUserEntity.getTelephone()) ? "" : oldContractUserEntity.getTelephone();
                String newTelephone = Strings.isNullOrEmpty(contractUserEntity.getTelephone()) ? "" : contractUserEntity.getTelephone();
                if(!oldTelephone.equals(newTelephone)) {
                    logContent += Strings.isNullOrEmpty(logContent) ? "修改合同用户“" + oldContractUserEntity.getUserAbbrev() + "”：电话由“" + oldTelephone + "”修改为“" + newTelephone + "”" : "，电话由“" + oldTelephone + "”修改为“" + newTelephone + "”";
                }
                //邮件
                String oldMail = Strings.isNullOrEmpty(oldContractUserEntity.getMail()) ? "" : oldContractUserEntity.getMail();
                String newMail = Strings.isNullOrEmpty(contractUserEntity.getMail()) ? "" : contractUserEntity.getMail();
                if(!oldMail.equals(newMail)) {
                    logContent += Strings.isNullOrEmpty(logContent) ? "修改合同用户“" + oldContractUserEntity.getUserAbbrev() + "”：邮件由“" + oldMail + "”修改为“" + newMail + "”" : "，邮件由“" + oldMail + "”修改为“" + newMail + "”";
                }
                //邮编
                String oldPostcode = Strings.isNullOrEmpty(oldContractUserEntity.getPostcode()) ? "" : oldContractUserEntity.getPostcode();
                String newPostcode = Strings.isNullOrEmpty(contractUserEntity.getPostcode()) ? "" : contractUserEntity.getPostcode();
                if(!oldPostcode.equals(newPostcode)) {
                    logContent += Strings.isNullOrEmpty(logContent) ? "修改合同用户“" + oldContractUserEntity.getUserAbbrev() + "”：邮编由“" + oldPostcode + "”修改为“" + newPostcode + "”" : "，邮编由“" + oldPostcode + "”修改为“" + newPostcode + "”";
                }
                //地址
                String oldAddress = Strings.isNullOrEmpty(oldContractUserEntity.getAddress()) ? "" : oldContractUserEntity.getAddress();
                String newAddress = Strings.isNullOrEmpty(contractUserEntity.getAddress()) ? "" : contractUserEntity.getAddress();
                if(!oldAddress.equals(newAddress)) {
                    logContent += Strings.isNullOrEmpty(logContent) ? "修改合同用户“" + oldContractUserEntity.getUserAbbrev() + "”：地址由“" + oldAddress + "”修改为“" + newAddress + "”" : "，地址由“" + oldAddress + "”修改为“" + newAddress + "”";
                }
                if(!Strings.isNullOrEmpty(logContent)){
                    LogUtil.operationLog(SystemOperationLogType.ContractUser_Operation.ordinal(), logContent, user.getUsername());
                }

                contractUserEntityMapper.update(contractUserEntity);
                res = "编辑成功";
            }
            return contractUserEntity;
        }catch (Exception ex) {
            throw ex;
        }
    }

    //删除合同用户
    @Override
    @Transactional(transactionManager = "mysqlTransactionManager")
    public String deleteByContractUserId(Integer contractUserId) {
        String res = "";
        try {
            //记录操作日志
            ContractUserEntity contractUserEntity = contractUserEntityMapper.selectByPrimaryKey(contractUserId);
            LogUtil.operationLog(SystemOperationLogType.ContractUser_Operation.ordinal(), "删除合同用户“" + contractUserEntity.getUserAbbrev() + "”", userContext.getCurrentUser().getUsername());

            //删除与机场的关联
            contractUserAirportEntityMapper.deleteByContractUserId(contractUserId);
            //删除与航司的关联
            contractUserAirlinesEntityMapper.deleteByContractUserId(contractUserId);
            //删除与用户的关联
            contractUserStaffEntityMapper.deleteByContractUserId(contractUserId);
            //删除与权限的关联
            contractUserPermissionEntityMapper.deleteByContractUserId(contractUserId);

            //删除计费账单
            billingBillEntityMapper.deleteByContractUserId(contractUserId);

            //删除合同用户
            contractUserEntityMapper.deleteByPrimaryKey(contractUserId);
            res = "删除成功！";
            return res;
        } catch (Exception ex) {
            throw ex;
        }
    }

    //编辑计费范围
    @Override
    @Transactional(transactionManager = "mysqlTransactionManager")
    public String editBillingRange(ContractUserEntityVO contractUserEntityVO){
        String res = "";
        try {
            Integer contractUserId = contractUserEntityVO.getContractUserId();
            String airportIds = contractUserEntityVO.getAirportIds();
            String airlineIds = contractUserEntityVO.getAirlineIds();

            //保存机场，删除后再存
            //记录操作日志
            String logContent = "";
            ContractUserEntity contractUserEntity = contractUserEntityMapper.selectByPrimaryKey(contractUserId);
            List<String> oldAirportNames = airportEntityMapper.selectAirportNamesByContractUserId(contractUserId);  //已关联的
            List<String> newAirportNames = airportEntityMapper.selectAirportNamesByIds(airportIds);         //重新关联的
            //获取差别
            Map<String,String> map = BillingTools.getDifference(oldAirportNames, newAirportNames);
            String less = map.get("less").toString();
            String more = map.get("more").toString();
            if(!Strings.isNullOrEmpty(less)){
                logContent = "修改合同用户“" + contractUserEntity.getUserAbbrev() + "”：计费范围删除机场（" + less.replace(",","、") + "）";
            }
            if(!Strings.isNullOrEmpty(more)){
                logContent += Strings.isNullOrEmpty(logContent) ? "修改合同用户“" + contractUserEntity.getUserAbbrev() + "”：计费范围增加机场（" + more.replace(",","、") + "）" : "，增加机场（" + more.replace(",","、") + "）";
            }
            if(!Strings.isNullOrEmpty(logContent)){
                LogUtil.operationLog(SystemOperationLogType.ContractUser_Operation.ordinal(), logContent, userContext.getCurrentUser().getUsername());
            }
            contractUserAirportEntityMapper.deleteByContractUserId(contractUserId);
            contractUserAirportEntityMapper.insertByBatch(contractUserId,airportIds);

            //保存航司，删除后再存
            //记录删除操作日志
            List<String> airlineNames1 = airlinesEntityMapper.selectAirlineNamesByContractUserId(contractUserId);  //已关联的
            List<String> airlineNames2 = airlinesEntityMapper.selectAirlineNamesByIds(airlineIds);         //重新关联的
            //获取差别
            map = BillingTools.getDifference(airlineNames1, airlineNames2);
            less = map.get("less").toString();
            more = map.get("more").toString();
            logContent = "";
            if(!Strings.isNullOrEmpty(less)){
                logContent = "修改合同用户“" + contractUserEntity.getUserAbbrev() + "”：计费范围删除航司（" + less.replace(",","、") + "）";
            }
            if(!Strings.isNullOrEmpty(more)){
                logContent += Strings.isNullOrEmpty(logContent) ? "修改合同用户“" + contractUserEntity.getUserAbbrev() + "”：计费范围增加航司（" + more.replace(",","、") + "）" : "，增加航司（" + more.replace(",","、") + "）";
            }
            if(!Strings.isNullOrEmpty(logContent)){
                LogUtil.operationLog(SystemOperationLogType.ContractUser_Operation.ordinal(), logContent, userContext.getCurrentUser().getUsername());
            }
            contractUserAirlinesEntityMapper.deleteByContractUserId(contractUserId);
            contractUserAirlinesEntityMapper.insertByBatch(contractUserId,airlineIds);
            res = "修改计费范围成功";
        }catch (Exception ex) {
            throw ex;
        }
        return res;
    }

    //查询机场，并设置是否选中
    @Override
    public List<ScAirportEntityVO> selectAirports(Integer contractUserId, Map<String, Object> map){
        List<ScAirportEntityVO> vos = Lists.newArrayList();
        //与合同用户绑定的机场
        List<Integer> airportIds = contractUserAirportEntityMapper.selectAirportIds(contractUserId);
        //全部机场
        List<ScAirportEntity> airportEntityList = airportEntityMapper.select(map);
        if (airportEntityList != null && airportEntityList.size() > 0) {
            ScAirportEntityVO vo;
            for (ScAirportEntity entity : airportEntityList) {
                vo = entity.toVO();
                if (airportIds != null && airportIds.contains(entity.getId())) {
                    vo.setChecked(true);
                }
                vos.add(vo);
            }
        }
        return vos;
    }

    //查询航司，并设置是否选中
    @Override
    public List<ScAirlinesEntityVO> selectAirlines(Integer contractUserId, Map<String, Object> map){
        List<ScAirlinesEntityVO> vos = Lists.newArrayList();
        //与合同用户绑定的航司
        List<Integer> airlineIds = contractUserAirlinesEntityMapper.selectAirlineIds(contractUserId);
        //全部机场
        List<ScAirlinesEntity> airlinesEntityList = airlinesEntityMapper.select(map);
        if (airlinesEntityList != null && airlinesEntityList.size() > 0) {
            ScAirlinesEntityVO vo;
            for (ScAirlinesEntity entity : airlinesEntityList) {
                vo = entity.toVO();
                if (airlineIds != null && airlineIds.contains(entity.getId())) {
                    vo.setChecked(true);
                }
                vos.add(vo);
            }
        }
        return vos;
    }

    //获取关联用户Tree
    @Override
    public List<PbStaffTreeVO> getAssociatedUsersTreeNode(Integer contractUserId, Map<String, Object> map){
        List<PbStaffTreeVO> vos = Lists.newArrayList();

        //与合同用户绑定的关联用户
        List<String> staffIds = contractUserStaffEntityMapper.selectLoginIds(contractUserId);

        //根节点
        PbStaffTreeVO rootNode_staff =
                new PbStaffTreeVO("0","0","部门",true);
        vos.add(rootNode_staff);

        //全部部门
        List<PbDepartmentEntity> departmentEntityList = departmentEntityMapper.select(map);
        if (departmentEntityList != null && departmentEntityList.size() > 0) {
            PbStaffTreeVO vo;
            for (PbDepartmentEntity entity : departmentEntityList) {
                vo = new PbStaffTreeVO(entity,true);
                vos.add(vo);
            }
        }

        //全部关联用户
        List<PbStaffEntity> staffEntityList = pbStaffEntityMapper.select(map);
        if (staffEntityList != null && staffEntityList.size() > 0) {
            PbStaffTreeVO vo;
            for (PbStaffEntity entity : staffEntityList) {
                vo = new PbStaffTreeVO(entity,true);
                if (staffIds != null && staffIds.contains(entity.getPB_LOGIN_ID())) {
                    vo.setChecked(true);
                }
                vos.add(vo);
            }
        }
        return vos;
    }

    //编辑关联用户
    @Override
    @Transactional(transactionManager = "mysqlTransactionManager")
    public String editAssociatedUsers(ContractUserEntityVO contractUserEntityVO){
        String res = "";
        try {
            Integer contractUserId = contractUserEntityVO.getContractUserId();
            String associatedUserIds = contractUserEntityVO.getAssociatedUserIds();

            //记录删除操作日志
            ContractUserEntity contractUserEntity = contractUserEntityMapper.selectByPrimaryKey(contractUserId);
            List<String> pbNames1 = pbStaffEntityMapper.selectPbNamesByContractUserId(contractUserId);
            List<String> pbNames2 = pbStaffEntityMapper.selectPbNamesByLoginIds(associatedUserIds);
            //获取差别
            Map<String,String> map = BillingTools.getDifference(pbNames1, pbNames2);
            String less = map.get("less").toString();
            String more = map.get("more").toString();
            String logContent = "";
            if(!Strings.isNullOrEmpty(less)){
                logContent = "修改合同用户“" + contractUserEntity.getUserAbbrev() + "”：删除关联用户（" + less.replace(",","、") + "）";
            }
            if(!Strings.isNullOrEmpty(more)){
                logContent += Strings.isNullOrEmpty(logContent) ? "修改合同用户“" + contractUserEntity.getUserAbbrev() + "”：增加关联用户（" + more.replace(",","、") + "）" : "，增加关联用户（" + more.replace(",","、") + "）";
            }
            if(!Strings.isNullOrEmpty(logContent)){
                LogUtil.operationLog(SystemOperationLogType.ContractUser_Operation.ordinal(), logContent, userContext.getCurrentUser().getUsername());
            }

            //保存关联用户，删除后再存
            contractUserStaffEntityMapper.deleteByContractUserId(contractUserId);
            if(!Strings.isNullOrEmpty(associatedUserIds)){
                contractUserStaffEntityMapper.insertByBatch(contractUserId,associatedUserIds);
            }
            res = "修改关联用户成功";
        }catch (Exception ex) {
            throw ex;
        }
        return res;
    }

    //一个登录用户不能被两个合同用户关联（如果选择的登陆用户已经被其他合同用户关联过，则系统进行提示“用户已经被合同用户关联，不能保存！”）
    @Override
    public String selectOtherContractUser(ContractUserEntityVO contractUserEntityVO){
        String res = "";
        for(String loginId : contractUserEntityVO.getAssociatedUserIds().split(",")){
            if(Strings.isNullOrEmpty(loginId)){
                continue;
            }
            List<Integer> list = contractUserStaffEntityMapper.selectOtherContractUserIds(loginId,contractUserEntityVO.getContractUserId());
            if(list != null && list.size() > 0){
                PbStaffEntity pbStaffEntity = pbStaffEntityMapper.findByLoginId(loginId);
                ContractUserEntity contractUserEntity = contractUserEntityMapper.selectByPrimaryKey(list.get(0));
                if(!Strings.isNullOrEmpty(res)) res += "、";
                res += pbStaffEntity.getPB_NAME() + "用户已经被" + contractUserEntity.getUserAbbrev() + "合同用户关联";
            }
        }
        if(!Strings.isNullOrEmpty(res)) res += "，不能保存！";
        return res;
    }

    //查询计费规则，并设置是否选中
    @Override
    public List<BillingRuleEntityVO> selectBillingRules(Integer contractUserId, Map<String, Object> map){
        List<BillingRuleEntityVO> vos = Lists.newArrayList();
        //与合同用户绑定的计费规则
        ContractUserEntity contractUserEntity = contractUserEntityMapper.selectByPrimaryKey(contractUserId);
        Integer bindBillingRuleId = contractUserEntity.getBillingRuleId();

        //全部计费规则
        List<BillingRuleEntity> billingRuleEntityList = billingRuleEntityMapper.select(map);
        if (billingRuleEntityList != null && billingRuleEntityList.size() > 0) {
            BillingRuleEntityVO vo;
            for (BillingRuleEntity entity : billingRuleEntityList) {
                vo = entity.toVO();
                if (bindBillingRuleId != null && bindBillingRuleId.equals(entity.getBillingRuleId())) {
                    vo.setChecked(true);
                }
                vos.add(vo);
            }
        }
        return vos;
    }

    //编辑计费规则
    @Override
    @Transactional(transactionManager = "mysqlTransactionManager")
    public String editBillingRule(ContractUserEntityVO contractUserEntityVO){
        String res = "";
        try {
            Integer contractUserId = contractUserEntityVO.getContractUserId();
            Integer billingRuleId = contractUserEntityVO.getBillingRuleId();

            ContractUserEntity contractUserEntity = contractUserEntityMapper.selectByPrimaryKey(contractUserId);

            //记录操作日志
            if(billingRuleId != contractUserEntity.getBillingRuleId()){
                BillingRuleEntity newBillingRuleEntity = billingRuleEntityMapper.selectByPrimaryKey(billingRuleId);
                if(contractUserEntity.getBillingRuleId() == null){
                    LogUtil.operationLog(SystemOperationLogType.ContractUser_Operation.ordinal(),
                            "修改合同用户“" + contractUserEntity.getUserAbbrev() + "”：增加计费规则“" + newBillingRuleEntity.getRuleAbbrev() + "”", userContext.getCurrentUser().getUsername());
                }else {
                    BillingRuleEntity oldBillingRuleEntity = billingRuleEntityMapper.selectByPrimaryKey(contractUserEntity.getBillingRuleId());
                    LogUtil.operationLog(SystemOperationLogType.ContractUser_Operation.ordinal(),
                            "修改合同用户“" + contractUserEntity.getUserAbbrev() + "”：计费规则由“" + oldBillingRuleEntity.getRuleAbbrev() + "”修改为“" + newBillingRuleEntity.getRuleAbbrev() + "”", userContext.getCurrentUser().getUsername());
                }
            }
            contractUserEntity.setBillingRuleId(billingRuleId);
            contractUserEntityMapper.update(contractUserEntity);
            res = "修改计费规则成功";
        }catch (Exception ex) {
            throw ex;
        }
        return res;
    }

    //查未指定计费规则的合同用户
    @Override
    public String selectNoBillingRule(){
        return contractUserEntityMapper.selectNoBillingRule();
    }
}